var speed= 10; 
var tiro: Transform;
var aerolito: Transform;
var explosao2: Transform;
var resetPosition: Transform;

static var morte = 0;


var posaerolito;

function Start () {
	posaerolito = Vector3 (Random.Range(0.0, 18.0), 3, 4);
}

function Update () { 
	

	networkView.RPC("locomover",RPCMode.All);

	if (Input.GetKeyDown(KeyCode.Space)) {
		
		networkView.RPC("fire",RPCMode.All);
		
		
	}

	if (morte ==3){
		//Application.LoadLevel("perdeu");
		//morte=0;
	}

	if (transform.localPosition.x >= 18.04804) {
		transform.localPosition.x = 2.466259;
	}

	if ( transform.localPosition.x <= 2.466258){
		transform.localPosition.x = 18.0488;
	}

}

@RPC
function locomover(){
	var x = Input.GetAxis("Vertical") * speed; 
	var z = Input.GetAxis("Horizontal") * speed; 
	GetComponent("CharacterController").SimpleMove(Vector3(x, 0, 0));
}

@RPC
function fire(){
	var novoObjeto = Instantiate(tiro, transform.position, transform.rotation); 
	Physics.IgnoreCollision(novoObjeto.collider, collider);
	novoObjeto.rigidbody.AddForce (0,0,-1200);
		   
	if (novoObjeto.localPosition.z <= -5) {
		Debug.Log ("destruiu");
	}
	
	if (Input.GetKeyUp (KeyCode.Space)){
		inimigo.velocidadearolito += 0.3;
	}
}

function OnTriggerEnter (aer : Collider){
	
	if (aer.tag =="GameController"){
	
		var explos = Instantiate(explosao2, transform.position, transform.rotation);
		
	/*
		transform.position.x = 14.19678;
		transform.position.y = 0.5264626;
		transform.position.z = 28.77859;
		aer.transform.position.z = 3;
		aer.transform.position.x = Random.Range(5, 15);
		
	*/
		this.transform.position = resetPosition.transform.position;	
		morte ++;
		
	}

}


